﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Domain.Rules
{
    /// <summary>
    /// 字符串最大长度
    /// </summary>
    [Serializable]
    public class MaxStringLengthRule : RuleBase
    {
        private readonly int _maxLen;

        public MaxStringLengthRule(
            int maxLen,
            int ruleId,
            string[] participatingLogicalFields,
            string fieldName, 
            object holder) :base(ruleId,participatingLogicalFields,fieldName,holder)
        {
            _maxLen = maxLen;
        }

        public MaxStringLengthRule(int maxLen, string filedName, object holder)
            : this(maxLen, 1, new string[0], "Note", holder)
        {
        }

        public override bool IsValid
        {
            get
            {
                string value = (string)base.GetValue();
                return value.Length <= _maxLen;
            }
        }
    }
}
